<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\service\ConfigService;
use think\facade\Config;
use think\facade\Db;
use think\facade\View;

class Main extends AdminController
{
    public $noNeedPermission = ['index'];

    /**
     * 概览页
     *
     * @Author tanruizheng
     * @DateTime 2021-07-09
     * @return void
     */
    public function index()
    {
        //查询数据库版本
        $mysqlVersion = Db::query('select version()');
        $mysqlVersion = $mysqlVersion && count($mysqlVersion) > 0 ? $mysqlVersion[0]['version()'] : '';
        $systemInfo = [
            'php_os' => PHP_OS,//操作系统
            'server_software' => $_SERVER['SERVER_SOFTWARE'],//运行环境
            'php_sapi_name' => php_sapi_name(),//php运行方式
            'mysql_version' => $mysqlVersion,//mysql版本号
            'database' => Config::get('database.connections.mysql.database'),//数据库名字
            'hostname' => Config::get('database.connections.mysql.hostname'),//数据库地址
            'sitename' => ConfigService::getConfig('sitename')['data'],//网站名称
            'upload_max_filesize' => ini_get('upload_max_filesize'),//上传附件限制
            'max_execution_time' => ini_get('max_execution_time').'秒',//执行时间限制
            'disk_free_space' => round(disk_free_space(".") / (1024 * 1024),2) . 'M',//剩余空间
        ];
        return View::fetch('index',[
            'systemInfo' => $systemInfo
        ]);
    }
}
